package com.net.xpay.core.validator;

import com.google.common.base.Strings;
import com.net.xpay.common.domain.User;
import com.net.common.exception.BusinessException;
import com.net.common.util.PhoneUtil;
import com.net.common.util.SerializationUtil;
import com.net.xpay.core.constant.PoseidonErrorCode;
import com.net.xpay.core.model.TaokeDetectionModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 2020/6/6 11:12

 */
@Slf4j
@Component
public class TaokeDetectionValidator {

    public void validateTaokeDetection(User user, TaokeDetectionModel detectionModel) {
        log.info("validateTaokeDetection params={}|userId={}", SerializationUtil.obj2String(detectionModel), user.getId());
       if (Strings.isNullOrEmpty(detectionModel.getTid())) {
           throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL, "淘宝订单号不能为空");
       }
       if (Strings.isNullOrEmpty(detectionModel.getWw())) {
           throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL, "旺旺号不能为空");
       }
       if (Strings.isNullOrEmpty(detectionModel.getBuyerMobile())) {
           throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL, "手机号不能为空");
       }
       detectionModel.setTid(detectionModel.getTid().trim());
       detectionModel.setBuyerMobile(detectionModel.getBuyerMobile().trim());
       detectionModel.setWw(detectionModel.getWw().trim());

       if (!PhoneUtil.isEffectiveMobile(detectionModel.getBuyerMobile())) {
           throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL, "手机号格式不正确");
       }
    }
}
